package com.kele.test.rabbitmq.controller;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageDeliveryMode;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("producer05_deadletter")
public class ProducerController_High5_DeadLetter {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("sendMessage")
    public String sendMessage(){
        for(int i=0;i<200;i++){
            sendMessage1(i);
        }

        return "OK";
    }
    public String sendMessage1(Integer id){

        rabbitTemplate.convertAndSend(
                "exchange_dlx_business_direct","business","Hello 1905A",
                (Message message)->{
                    message.getMessageProperties()
                            .setReceivedDeliveryMode(MessageDeliveryMode.PERSISTENT);
                    message.getMessageProperties().setMessageId(id.toString());
                    return message;
                });

        return "OK";
    }
}
